package com.efun.framework.validate;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author kinven on 17-8-21.
 */
@Configuration
@EnableConfigurationProperties({ValidatorProperties.class})
public class ValidatorAutoConfiguration extends WebMvcConfigurerAdapter {

    private final ValidatorProperties validatorProperties;

    public ValidatorAutoConfiguration(ValidatorProperties validatorProperties){
        this.validatorProperties = validatorProperties;
    }

    @Bean
    public ValidatorManager validatorManager(){
        ValidatorManager validatorManager = new ValidatorManager();
        validatorManager.setDefaultValidator(validatorProperties.getRequest().getDefaultValidators());
        return validatorManager;
    }

    public void addInterceptors(InterceptorRegistry registry) {

    }
}
